function [mean_sort_act]=pop_act_sorted_multiTime(ExpGroup)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   mean sorted population response (feedback, playback etc.) over several experimental
%   sessions

%   code (by columns in mean_sort_act):
%   1-15 feedback
%   16-45 playback
%   46-47 baseline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tmp_data_dir = '\\KELLER-RIG1-ANA\RawData\';
adata_dir = '\\argon.fmi.ch\keller.g\AData\';
mean_sort_act=zeros(length(ExpGroup),47);
% pop_av_act=zeros(length(ExpGroup),1);
for fnd=1:length(ExpGroup)
    display(['Exp: ' num2str(ExpGroup(fnd)) ' *****************************']);
    [adata_file,mouse_id,userID]=find_adata_file(ExpGroup(fnd),adata_dir);
    orig=load([adata_dir userID '\' mouse_id '\' adata_file],'ROIs','nbr_frames','aux_files');
    aux_data=[];
    try
        for ind=1:length(orig.aux_files)
            if exist([tmp_data_dir userID '\' mouse_id '\' orig.aux_files{ind}],'file');
                disp(['loading file ' orig.aux_files{ind} ' from local tmpdata directory']);
                curr_load_path=[tmp_data_dir userID '\' mouse_id '\' orig.aux_files{ind}];
            else
                disp(['loading file ' orig.aux_files{ind} ' from the network RawData directory']);
                curr_load_path=[rdata_dir userID '\' mouse_id '\' orig.aux_files{ind}];
            end
            tmp_data=load_lvd(curr_load_path);
            tmp_frames=get_frame_times(tmp_data(2,:));
            
            if orig.nbr_frames(ind)~=length(tmp_frames)
                if max(diff(tmp_frames))/median(diff(tmp_frames))<1.5 & length(tmp_frames)>orig.nbr_frames(ind)
                    disp('NC WARNING! Probably scanning too fast for FPGA to stop in the same frame')
                    disp(['--- ' num2str(length(tmp_frames)-orig.nbr_frames(ind)) ' frames too many ---'])
                    tmp_data(2,tmp_frames(orig.nbr_frames(ind)+1):end)=0;
                else
                    disp('CRITICAL WARNING! - aux data longer than it should be.')
                    [~,last_bad_frame]=max(diff(tmp_frames));
                    tmp_data=tmp_data(:,ceil(mean([tmp_frames(last_bad_frame) tmp_frames(last_bad_frame+1)])):end);
                end
            end
            aux_data(:,end+1:end+length(tmp_data))=tmp_data;
        end
        frame_times=get_frame_times(aux_data(2,:));
    catch
        disp('Did not load aux data')
    end
    [mean_sort_act(fnd,:)]=sort_pop_act(aux_data,frame_times,orig.ROIs,orig.nbr_frames,0);
end

% mis_f=mean_sort_act(:,3);
% mis_2=mean_sort_act(:,5);
% mis=mean([mis_f mis_2],2);
% bas_f=mean_sort_act(:,6);
% bas_2=mean_sort_act(:,8);
% bas=mean([bas_f bas_2],2);
% 
% new_mean(:,1)=mean_sort_act(:,1);
% new_mean(:,2)=mean_sort_act(:,2);
% new_mean(:,3)=mis;
% new_mean(:,4)=mean_sort_act(:,4);
% new_mean(:,5)=bas;
% new_mean(:,6)=mean_sort_act(:,7);
% new_mean(:,7)=mean_sort_act(:,9);
% new_mean(:,8)=mean_sort_act(:,10);
% 
% leg_list={'feedback' 'playback' 'mismatch' 'mismatch.local' 'baseline' 'baseline.local' 'run.dark' 'bas.dark'};
% figure;
% plot(new_mean)
% legend(leg_list)